﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLBH.DataModel;
using QLBH.Base;
using QLBH.Model.Controller;
using QLBH.ModelInterface;
namespace QLBH.FeatureModel
{
   public class PhieuMuaHangChiTietModel:PhieuMuaHangModel,IPhieuMuaHangChiTietModel
    {
       public IList<IMatHangItemModel> MatHang { set; get; }

       public PhieuMuaHangChiTietModel()
           :base()
       {
           MatHang = new List<IMatHangItemModel>();
       } 
       public PhieuMuaHangChiTietModel(IPhieuMuaHangModel model)
           :base()
       {
           try
           {               
               this.MaKho = model.MaKho;
               this.MaPhieu = model.MaPhieu;
               this.NgayGui = model.NgayGui;
               this.NgayTao = model.NgayTao;
               this.SoPhieu = model.SoPhieu;
               this.TenKho = model.TenKho;
               this.TongTien = model.TongTien;
               this.UserID = model.UserID;
               this.UserName = model.UserName;

               MatHang = new List<IMatHangItemModel>(); 
               var items = QLPhieuMuaHangChiTietController.GetInstance().FindBy(mh => mh.MUAHANGID == model.MaPhieu).ToList();

               if (items != null)
               {
                   foreach (PHIEUMUAHANGCT entity in items)
                   {
                       MatHangItemModel modelitem = new MatHangItemModel();
                       modelitem.InitFromEntity(entity);

                       MatHang.Add(modelitem);
                   }
               }
           }
           catch (System.Exception ex)
           {
               throw ex;
           }
       }      
    }
}
